package main

import "fmt"

func search(nums []int, target int) int {
	left := 0
	right := len(nums) - 1
	index := 0
	for left <= right {
		index = left + (right-left)/2
		if nums[index] < target {
			left = index + 1
		} else if nums[index] > target {
			right = index - 1
		} else {
			return index
		}
	}
	return -1
}
func search2(nums []int, target int) int {
	left := 0
	right := len(nums)
	for left < right {
		middle := left + (right-left)/2
		if nums[middle] < target {
			left = middle + 1
		} else if nums[middle] > target {
			right = middle
		} else {
			return middle
		}
	}
	return -1
}

func main() {
	nums := []int{1, 2, 3, 4, 5, 6, 7}
	fmt.Println(search(nums, 8))
}
